package fr.univsavoie.tatiana2dvisualisation;

import java.util.Vector;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.swt.widgets.Canvas;

import fr.emse.tatiana.replayable.IReplayableModel;

public class PointsDrawer {
	private IReplayableModel model;
	private LightweightSystem lws;
	private DrawCondition defaultdraw;
	private Vector<DrawCondition> conditions = new Vector<DrawCondition>();
	private Figure contents;

	// no longer used, kept for reference
	
	public PointsDrawer(IReplayableModel model, Canvas c) {
		this.model=model;
		this.lws = new LightweightSystem(c); 
		int xcol = model.getFacetCol("x");
		int ycol = model.getFacetCol("y");	
		int pressurecol = model.getFacetCol("p");
//		defaultdraw = new DrawCondition(null,null,ColorConstants.blue,ColorConstants.gray,ColorConstants.red,xcol,ycol,pressurecol);
//		if (model.getFacetCol("type")>=0) {
//			DrawCondition eyecond = new DrawCondition("type","eye",null,null,ColorConstants.red,xcol,ycol,pressurecol);
//			eyecond.setCurrentShape(DrawCondition.DISK);
//			DrawCondition pencond = new DrawCondition("type","pen",ColorConstants.blue,ColorConstants.gray,ColorConstants.red,xcol,ycol,pressurecol);
//			conditions.add(pencond);
//			conditions.add(eyecond);
//		}
		contents = new Figure();
		XYLayout contentsLayout = new XYLayout();
		contents.setLayoutManager(contentsLayout);
	}
	
	public void draw(int start, int end) {
		draw(start,end,model.getFirstTime()-1000);
	}
	
	public void draw(int start, int end, long currenttime) {

//		
//		for (int i=start; i<end; i++) {
//			Object current = model.getEvent(i);
//			int type = DrawCondition.PRESENT;
//			if (model.getBeginTime(current)<currenttime-20) {
//				type = DrawCondition.PAST;
//			} 
//			if (model.getBeginTime(current)>currenttime+20) {
//				type = DrawCondition.FUTURE;
//			} 
//			if (conditions.isEmpty()) {
//				addFigure(defaultdraw.draw(model, current, type));	
//			} else {
//				for (DrawCondition condition: conditions) {
//					addFigure(condition.draw(model, current, type));	
//				}
//			}
//
//		}
//		lws.setContents(contents);
	}

	private void addFigure(IFigure fig) {
		if (fig!=null) contents.add(fig);
		
	}
	
}
